<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>分类管理</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/snow.css"/>
    <script type="text/javascript" src="../layui/layui.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/x-layui.js" charset="utf-8"></script>
</head>
<body>
<div class="wrap">
    <table id="demo" lay-filter="demo" style="width: 50px;height: auto"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="edit">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>

    <script>
        layui.use('table', function () {
            var table = layui.table;
            var $ = layui.$;
            //监听工具条
            table.on('tool(demo)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('真的删除行么', function (index) {
                        $.post("../deleteById.do?id=" + data.classId, function (data) {
                            if (data.success) {
                                layer.msg(data.message, {icon: 1, time: 2000, offset: '100px'})
                                layer.close(index);
                                obj.del();
                            } else {
                                layer.msg(data.message, {icon: 2, time: 2000, anim: 6, offset: '100px'})
                                layer.close(index);
                                layui.table.reload('demo');
                            }
                        }, "json");
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    x_admin_show("菜系编辑", "foodclass-edit.html?classId=" + data.classId, 500, 350);
                }
            });
            table.render({
                elem: '#demo'
                ,
                height: 350
                ,
                url: '../findAll.do' //数据接口
                ,
                page: true //开启分页
                ,
                cellMinWidth: 80
                ,
                limit: 5
                ,
                limits: [5, 10, 15, 20]
                ,
                title: '菜品管理'
                ,
                width: '800'
                ,
                toolbar: "<div><a class='layui-btn layui-btn-sm' onclick='x_admin_show(\"菜系添加\",\"foodclass-add.html\",500,250);'>添加</a></div>"
                ,
                defaultToolbar: ['filter', 'print', 'exports', {
                    title: '分类管理' //标题
                    , layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
                    , icon: 'layui-icon-tips' //图标类名
                }]
                ,
                cols: [[ //表头
                    {field: 'classId', title: 'ID', sort: true, fixed: 'left'}
                    , {field: 'className', title: '菜系'}
                    , {fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo'}
                ]]

            });
        });
    </script>
    <script src="../js/mouse.js"></script>

    <!--爱心雨-->
    <!--<script type="text/javascript" src="js/jquery.min.js" ></script>

    <script src="https://cdn.bootcss.com/JQuery-Snowfall/1.7.4/snowfall.jquery.min.js"></script>
    <script>
        $(document).snowfall({flakeCount : 100, maxSpeed :5});
    </script>-->
</div>
</body>
</html>
